package com.ang.propagation.tt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class TTService2 {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * inset1无异常
     * @param i
     */
    @Transactional
    public void insert1(int i){
        System.out.println("------------------:"+i);
        jdbcTemplate.update("insert into t_user (name) value (?)", String.format("insert1-%d",i));
    }


    /**
     * insert2抛异常
     * @param i
     */
    @Transactional
    public void insert2(int i){
        System.out.println("------------------:"+i);
        jdbcTemplate.update("insert into t_user (name) value (?)", String.format("insert2-%d",i));
        if(i==5){
            int a = 1/0;
        }
    }
}
